package com.ndp.fb.fbagent.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ndp.fb.fbagent.service.impl.paramadapter.FacebookParamAdapter;
import com.restfb.DefaultFacebookClient;
import com.restfb.Parameter;
import com.restfb.Version;
import org.junit.Test;

import java.util.Properties;

/**
 * Created by infi.he on 2015/7/13.
 */
public class DeleteCampain {

    String token = "CAAEJqYBYwW0BAPatBTdpxbVBi1ZB6yFxpxkYvcbpjAjEFMLsfGEo593CRyzPDZBnOxNXlk3MAV8Jg4rR0bGTKeyv0DnOFS5aplpl8NsgomMUpU2BdkdcTdVVfBKiWoEsLQE41OuERrzxxQXzzvK542SQLuZBuqZCYzG4gJm6KS6nYTFfQygJ5ZBYJnoZBGQDD1NgvdBRtYXwlPIS3RVaw8";

    DefaultFacebookClient defaultFacebookClient = new DefaultFacebookClient(token, Version.Version_2_6);
    FacebookParamAdapter facebookParamAdapter = new FacebookParamAdapter();

    {
        Properties prop = System.getProperties();
        prop.setProperty("https.proxyHost", "proxy.dy");
        prop.setProperty("https.proxyPort", "3128");
    }

    @Test
    public void test1() {

        Parameter limit = Parameter.with("limit",10000);
        String s = defaultFacebookClient.makeRequest("act_1380154175555045/adcampaign_groups", false, false, null, new com.restfb.Parameter[]{limit});
        JSONObject jsonObject = JSON.parseObject(s);
        JSONArray data = jsonObject.getJSONArray("data");


        Parameter delete = Parameter.with("campaign_group_status", "DELETED");

        int i = 0;
        int len = data.size();
        for (Object o : data) {
            JSONObject cam = (JSONObject)o;
            String id = cam.getString("id");

            String s1 = defaultFacebookClient.makeRequest(id, false, true, null, new Parameter[]{delete});
            System.out.println(id);
            System.out.println(s1);
            System.out.println("总共>>>"+len+" , 已经删除 >>>"+(++i));
            try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
